package com.iwords.android;

import android.os.Vibrator;
import android.view.View;
import android.widget.Toast;


/**WordKnownLevel点击事件监听器*/
class LevelViewsListener implements View.OnClickListener{
	private LevelView level;
	private ShowWord showWord;
	LevelViewsListener(LevelView level, ShowWord showWord){
		this.level = level;
		this.showWord = showWord;
	}
	private void vibrate(){
		Vibrator mVibrator = (Vibrator)showWord.getApplication().getSystemService(android.app.Service.VIBRATOR_SERVICE);
		mVibrator.vibrate(new long[]{50,50},-1);
	}
    public void onClick(View v) {
    	this.vibrate();
        //判断当前队列有没有待复习词汇，没有，则给出提示信息
    	//System.out.println("LevelViewsListener.onClick() level.levelCountIndex="+level.levelCountIndex);
    	//System.out.println("LevelViewsListener.onClick() showWord.iWordsApp.getReviewQueue(level.levelCountIndex).size()="+showWord.iWordsApp.getReviewQueue(level.levelCountIndex).size());
    	if(level.levelCountIndex == 0){
    		Toast t1 = Toast.makeText(showWord.getApplication(), "Done队列只有当天加入的词汇可以左右移动。", Toast.LENGTH_SHORT);
			t1.show();
    	}
    	if(showWord.iWordsApp.getCurrentLibStatus().getGreenCount(level.levelCountIndex)<1){
	        //System.out.println("LevelViewsListener.onClick(View v) before Toast");
    		if(level.levelCountIndex == 6){//点击新词队列，但词汇数为零，则问是否需要再取一批
    			showWord.showMoreDialog();
    		}else{
		        Toast t1 = Toast.makeText(showWord.getApplication(), "当前等级没有待复习词汇。", Toast.LENGTH_SHORT);
				t1.show();
    		}
	        //System.out.println("LevelViewsListener.onClick(View v) after Toast");
	        return;
    	}
    	if(showWord.wordsQueueManager.getCurrentQueueIndex() != level.levelCountIndex){
    		showWord.changeQueue(level.levelCountIndex);
    	}
    }
}
